serializeToToml

fun <T : Any> serializeToToml(config: T, errorBuilder: MutableList<String>, flags: Byte = 1): TomlElement

Serialize a config class to a TomlElement

Custom serializer, powered by TomlKt. Serialization occurs in two ways

  1. EntrySerializer elements are serialized with their custom serializeEntry method

  2. "Raw" properties and fields are serialized with the TomlKt by-class-type serialization.

Will serialize the available TomlAnnotations, for use in proper formatting, comment generation, etc. Note that if you register the config on the client side, TOML formatting may not be critical, as the user will generally edit the config in-game.

  • TomlHeaderComment and Version: Will add top-of-file comments above the

  • TomlComment: Adds a comment to the Toml file output. Accepts single line ("..") or multi-line ("""..""") comments

  • TomlBlockArray: marks a list or other array object as a Block Array (Multi-line list). Default items per line is 1

  • TomlInline: Marks that the annotated table or array element should be serialized as one line. Overrides TomlBlockArray

  • TomlMultilineString: Marked string parses to file as a multi line string

Should be called as a matched pair to deserializeFromToml. Ex: if ignoreNonSync is false on one end, it needs to be false on the other.

Return

Returns a TomlElement of the serialized config

Author

fzzyhmstrs

Since

0.2.0

Parameters

T

Type of the config to serialize. Can be any Non-Null type.

config

the config instance to serialize from

errorBuilder

the error list. error messages are appended to this for display after the serialization call

flags

default IGNORE_NON_SYNC. With the default, elements with the NonSync annotation will be skipped. See the flag options below to serialize the entire config (ex: saving to file), fully syncing (ex: initial sync server -> client), etc.

  • CHECK_NON_SYNC: Byte = 0

  • IGNORE_NON_SYNC: Byte = 1

  • CHECK_RESTART: Byte = 2

  • IGNORE_NON_SYNC_AND_CHECK_RESTART: Byte = 3

  • IGNORE_VISIBILITY: Byte = 4